package com.course.business.controller.admin;

import com.course.server.common.Result;
import com.course.server.dto.CategoryDto;
import com.course.server.service.CategoryService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.constraints.NotBlank;

/**
 * @author: Durian
 * @date: 2021/5/2 20:43
 */
@RestController
@RequestMapping("/admin/categories")
public class CategoryController {
    /**
     * 用于日志记录使用
     */
    public static final String BUSINESS_NAME = "课程分类";

    @Resource
    private CategoryService categoryService;

    /*@GetMapping
    public Result list(@Validated PageRequest request) {
        return Result.success(categoryService.list(request.getPage(), request.getSize()));
    }*/

    @GetMapping
    public Result listAll() {
        return Result.success(categoryService.listAll());
    }

    @PostMapping
    public Result save(@RequestBody @Validated CategoryDto categoryDto) {
        categoryService.save(categoryDto);
        return Result.success();
    }

    @DeleteMapping("{categoryId}")
    public Result delete(@PathVariable("categoryId") @NotBlank(message = "待删除分类ID不能为空") String categoryId) {
        categoryService.delete(categoryId);
        return Result.success();
    }


}
